#include <iostream>
#include <climits>
int MemoizedCutRodAux(int* p, int n, int* r){
if(r[n]>=0) return r[n];
int q;
if(n==0) q=0;
else{
q=INT_MIN;
for(int i=1; i<=n; ++i){
q=std::max(q, p[i-1]+MemoizedCutRodAux(p, n-i, r));
}
}
r[n]=q;
return q;
}
int MemoizedCutRod(int* p, int n){
int r[n+1];
for(int i=0; i<n+1; ++i) r[i]=INT_MIN;
return MemoizedCutRodAux(p, n, r);
}
int main(void){
int p[]={1, 5, 8, 9, 10, 17, 17, 20, 24, 30};
int n=sizeof(p)/sizeof(int);
int result=MemoizedCutRod(p, n);
std::cout<<result<<std::endl;
return 0;
}